package com.handu.luna.core.domain;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.springframework.data.domain.Sort;

import com.handu.luna.core.domain.article.ArticleCategory;
import com.handu.luna.core.domain.goods.Brand;
import com.handu.luna.core.domain.goods.Category;


public class Mall  extends BaseDomain{
	
	private List<Brand> brands;
	private List<Category> categories;
	private List<Category> allCategories;// 用于后台管理用的无层级结构的全部分类
	
	//文章分类
	private List<ArticleCategory> articleCategories;
	private List<ArticleCategory> allArticleCategories;
	
	public void init(){
		List<Category> list=context.getCategoryRepository().findAll(new Sort("id"));
       
		this.categories=new ArrayList<Category>();
		this.allCategories=new LinkedList<Category>();
		for(Category each : list){
			//if(each.getSubCategories()!=null)each.getSubCategories().clear();
			if(each.getParentId()==0){
				this.categories.add(each);
				each.initSubCategories(list);
			}
		}		
		for(Category each : categories){
			each.addSelfToList(allCategories);
		}		
	}
	
	//文章分类
	public void articleInit(){
		List<ArticleCategory> list = context.getArticleCategoryRepository().findAll();
		//list.add(0,new ArticleCategory(0,"顶级分类"));
		this.articleCategories = new ArrayList<ArticleCategory>();
		this.allArticleCategories = new LinkedList<ArticleCategory>();
		for(ArticleCategory each : list){
			//if(each.getSubCategories()!=null)each.getSubCategories().clear();
			if(each.getParent_id()==0){
				this.articleCategories.add(each);
				each.initSubArticleCategory(list);
			}	
		}
		for(ArticleCategory each : articleCategories){
			each.addSelfToListArticle(allArticleCategories);		
		}		
	}
	
	public List<Category> getAllCategories() {
		return allCategories;
	}
	public void setAllCategories(List<Category> allCategories) {
		this.allCategories = allCategories;
	}
	public List<Brand> getBrands() {
		return brands;
	}
	public void setBrands(List<Brand> brands) {
		this.brands = brands;
	}
	public List<Category> getCategories() {
		return categories;
	}
	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}
	
	//文章分类
	public List<ArticleCategory> getArticleCategories() {
		return articleCategories;
	}
	public void setArticleCategories(List<ArticleCategory> articleCategories) {
		this.articleCategories = articleCategories;
	}
	public List<ArticleCategory> getAllArticleCategories() {
		return allArticleCategories;
	}
	public void setAllArticleCategories(List<ArticleCategory> allArticleCategories) {
		this.allArticleCategories = allArticleCategories;
	}
	
    
}
